/**
 * @file graph_edit_001.cpp
 *
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2018. All rights reserved.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string.h>
#include "graph_utils.h"
#include "utils.h"
using namespace std;
using namespace ge;


bool CreateGraph(GraphPtr &graph, AscendString graph_name)
{
    auto shape_data = vector<int64_t>({ 1, 1, 28, 28 });
    TensorDesc desc_data(ge::Shape(shape_data), FORMAT_ND, DT_FLOAT16);

    // data op
    auto data = op::Data("data");
    data.update_input_desc_x(desc_data);
    data.update_output_desc_y(desc_data);
    auto add = op::Add("add").set_input_x1(data).set_input_x2(data);

    std::vector<Operator> inputs { data };
    std::vector<Operator> targets { add };
    
    graph =  Graph::ConstructFromInputs(inputs, graph_name);
    graph->SetTargets(targets);
    return true;
}

int main(int argc, char *argv[])
{
    // Genetate graph
    GraphPtr graph;
    bool ret;

    AscendString graph_name("IrGraph");
    ret = CreateGraph(graph, graph_name);
    if (!ret) {
        ERROR_LOG("Create Graph and set input output Failed");
        return OPENCANN_FAILED;
    }
    INFO_LOG("Create Graph and set input output Success");
    
    // Get Graph Name
    AscendString gName;
    graphStatus ret_g;
    ret_g = graph->GetName(gName);
    if (ret_g != GRAPH_SUCCESS || gName != graph_name) {
        ERROR_LOG("Get GraphName Failed");
        return OPENCANN_FAILED;
    } else {
        INFO_LOG("Get GraphName Success");
    }
    return OPENCANN_SUCCESS;
}
